<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //
        let p = new Promise((resolve,reject) => {
            if(Math.random() > 0.5){
                resolve("成功了")
            }else{
                reject("失败了")
            }
        })

        p.then(res =>{
            console.log(res)
        })
        .catch(err => {
            console.log(err)
        })

        //async 用于修饰函数 被他修饰的函数，返回的一定是promise

        async function fn(){
            return 1
        }
        // 返回了个promise
        console.log(fn())
        fn().then(res => {
            console.log(res)//1
        })

        async function fn2(){
            // Promise.reject直接返回失败状态
            // Promise.resolve直接返回成功状态
            return Promise.reject(3)
        }
        // 返回了个promise
        console.log(fn())
        fn2().catch(err => {
            console.log(err);//3
        })
    </script>
</body>
</html>